<script src="./mine.component.js"></script>
<style src="./mine.css" scoped></style>
<template>
	<view class="">
		<view class="bg-white">
			<view v-if="!hasLogin" class="flex solid-bottom padding align-center">
				<view class="cu-avatar xl round  cuIcon-my"></view>
				<view class="padding-sm margin-xs text-black text-content">
					<view class="content text-xl"  @tap="bindLogin">登录<text class="cuIcon-right"></text></view>
				</view>
			</view>
			<view v-else class="flex solid-bottom padding align-center">
				<view style="position: relative;">
					<image class="cu-avatar xl round" :src="avator" mode=""></image>
				</view>
				<view  class="flex align-center basis-xl justify-between">
					<view class="padding-sm margin-xs text-black text-content">
						<view class="content flex align-center">
							<view class="padding-right">
								<view class="flex align-center">
									<text class="padding-right text-xl">{{nickName}}</text>
									<text class="text-red" v-if="uerInfo.authIdentity==1"  @tap="showshiming">已实名</text>
									<text class="text-red" v-else  @tap="showshiming">未实名</text>
								</view>
								<view>{{uerInfo.phone}}</view>
							</view>
							
						</view>
					</view>
					<text class="text-xl text-gray cuIcon-right "></text>
				</view>
			</view>
		</view>
		<view class="cu-list menu sm-border margin-top  margin-bottom-xl">
			<view class="cu-item" v-if="hasLogin">
				<view class="content align-center text-cut">
					<text class="cuIcon-rank text-red"></text>
					<text class="text-black" v-if="sourceCompanyList.length">所属企业：
						<text v-for="(item,index) in sourceCompanyList" :key="index" class="padding-right">
							{{item.companyName}}
						</text>
					</text>
					<text v-else>所属企业</text>
				</view>
			</view>
			<!-- <view class="cu-item arrow" @click="navTo('/pages/setting/setting')">
				<view class="content flex align-center">
					<text class="cuIcon-settings text-red"></text>
					<text class="text-black">设置</text>
				</view>
			</view> -->
			<view class="cu-item arrow" @click="makePhoneCall">
				<view class="content flex align-center">
					<text class="cuIcon-phone text-red"></text>
					<text class="text-black">联系我们</text>
				</view>
			</view>
			<view class="cu-item arrow" @click="navTo('/pages/about/about')">
				<view class="content flex align-center">
					<text class="cuIcon-info text-red"></text>
					<text class="text-black">关于薪闪付</text>
				</view>
			</view>
		</view>
		
		<view class="cu-list menu" v-if="hasLogin">
			<view class="cu-item margin-top-xs" @click="toLogout" style="min-height:100upx;">
				<view class="content text-center">
					<text class="text-red">退出登录</text>
				</view>
			</view>
		</view>
		
		<!-- <view class="padding flex flex-direction">
			<button class="cu-btn bg-red margin-tb-sm lg" @click="moveToSubpackage">move to subpackage page</button>
		</view> -->
	</view>
</template>
<script>
	import {
		mapState,
	    mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				nickName:"",
				avator:"",
				sourceCompanyList:'',//企业列表
			};
		},
		computed: mapState(['hasLogin','uerInfo']),
		mounted() {
			this.loginUser();
			this.sourceCompany();
		},
		onShow(){
			this.loginUser();
			this.sourceCompany();
		},
		onPullDownRefresh() {
		/* 	this.reload = true;
			this.last_id = ''; */
			/* this.getBanner();
			this.getList(); */
			this.loginUser();
		},
		methods:{
			...mapMutations(['logout','login','setToken']),

			/* navTo(url){
				this.$api.msg(`跳转到${url}`);
			}, */
			makePhoneCall(){
				uni.makePhoneCall({
				    phoneNumber: '400-886-5123'
				});
			},
			navTo(url){
				if(!this.hasLogin){
					url = '../login/login';
				} 
				uni.navigateTo({  
					url
				})
			},
			bindLogin() {
				uni.navigateTo({
					url: '../login/login',
				});
			},
			showshiming(){
				if(this.uerInfo.authIdentity==1){
					uni.navigateTo({
						url: '../certidsresults/certidsresults',
					});
				}else{
					uni.navigateTo({
						url: '../certids/certids',
					});
				}
			},
			//退出登录
			toLogout(){
				uni.showModal({
					content: '确定要退出登录吗?',
					success: (e)=>{
						if(e.confirm){
							/* this.logout();
							setTimeout(()=>{
								uni.navigateTo({
									url: '../login/login'
								})
							}, 200) */
							var token = uni.getStorageSync('token');
							uni.request({
								url: this.$serverUrl+'/isalary/login/logout',
								method:'GET',
								header: {
									'content-type': 'application/x-www-form-urlencoded', 
									Authorization:token
								},
								success: (res) => {
									if (res.data.code == 0) {
										uni.showToast({
											icon: 'success',
											title: res.data.msg
										});
										this.logout();
										setTimeout(()=>{
											uni.navigateTo({
												url: '../login/login'
											});
										}, 500)
									}else {
										uni.showToast({
											icon: 'none',
											title: res.data.msg
										});
									}
							
								},
								fail:function(e){
									
								}
							})
							
						}
					}
				});
			},
			// renzhengTips(){
			// 	uni.showToast({
			// 		icon:'none',
			// 		title: '暂无店铺，先去实名认证'
			// 	});
			// 	setTimeout(()=>{
			// 		uni.navigateTo({
			// 			url: '../certids/certids'
			// 		});
			// 	}, 1000)
			// },
			loginUser(){
				uni.request({
					url: this.$serverUrl+'/isalary/my/userInfo',
					method: "GET",
					header: {
						"Content-Type": "application/x-www-form-urlencoded",  
						"Authorization":uni.getStorageSync('token')
					},
					success: (e) => {
						uni.stopPullDownRefresh();
						if (e.data.code == 0) {
							this.login(e.data.data);
							
							if(uni.getStorageSync('nickName') ||  uni.getStorageSync('avator')){
								this.nickName = uni.getStorageSync('nickName');
								this.avator = uni.getStorageSync('avator');
							}else{
								this.nickName = e.data.data.nickName;
								this.avator = e.data.data.avator;
							}
						}else if(e.data.code == 4000) {
										
						}else{
							uni.showToast({
								icon: 'none',
								title: e.data.msg
							});
						}
					}
				})
			},
			sourceCompany(){
				uni.request({
					url: this.$serverUrl+'/isalary/my/sourceCompany',
					method:'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded', 
						Authorization:uni.getStorageSync('token')
					},
					success: (res) => {
						if (res.data.code == 0) {
							this.sourceCompanyList = res.data.data;
						} else if (res.data.code == 1001 || res.data.code == 4000) {
							
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
				
					},
					fail:function(e){
						
					}
				})
		}
		
	},
		
	}
</script>
